package com.example.demo.controller;

import com.example.demo.model.JieDaiBao;
import com.example.demo.model.entity.Boom;
import com.example.demo.service.IJieDaiBaoService;
import com.example.demo.util.excel.GeneralExcelPoi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Created by Administrator on 2018/2/26.
 */
@Controller
@RequestMapping("jiedaibao")
public class JieDaiBaoController {

    @Autowired
    private IJieDaiBaoService jieDaiBaoService;

    @RequestMapping(value = "/data/export", method = RequestMethod.POST)
    @ResponseBody
    public void export(@RequestParam MultipartFile file, HttpServletResponse resp) throws Exception {
//        GeneralExcelPoi poi = new GeneralExcelPoi();
//        List<String> list = poi.parseExcel(file.getInputStream(), String.class);
//        List<JieDaiBao> jieDaiBaoList = jieDaiBaoService.getJieDaiBaoList(list);
//        if (!CollectionUtils.isEmpty(jieDaiBaoList)) {
//            poi.exportExcel(resp, jieDaiBaoList, "export");
//        }

    }


    @RequestMapping(value = "/data/import", method = RequestMethod.POST)
    @ResponseBody
    public void export(@RequestParam MultipartFile file) throws Exception {
        GeneralExcelPoi poi = new GeneralExcelPoi();
        List<String> list = poi.parseExcel(file.getInputStream(), String.class);
        jieDaiBaoService.importData(list);
    }

    @RequestMapping(value = "/data/boom", method = RequestMethod.GET)
    @ResponseBody
    public void export(String date, HttpServletResponse response) throws Exception {
        GeneralExcelPoi poi = new GeneralExcelPoi();
        List<Boom> boomList = jieDaiBaoService.getBoomListByDate(date);
        poi.exportExcel(response, boomList, "export" + date + ".xlsx");
    }
}
